import requests
import re

# # 构造url
# url = r'http://172.16.22.108:8080/bsams/front/login.do'
# resp = requests.get(url)
# print(resp.cookies)     # 获取到的是cookiesjar格式的，无法直接使用
# print(resp.cookies.get_dict())   # 转换为字典格式
url = r'http://172.16.22.108:8080'
# 登录数据
id = 1
username = 'zz01'
password = '123456'
vericode = 'shtd'

# 构造url

url_first = rf'{url}/bsams/front/login.do'
url_vericode = rf'{url}/bsams/front/vericode.do'
# 资产管理
url_asset = rf'{url}/bsams/front/asset/asset_list.do'

# 构造 data
data = {
    'taskId': id,
    'loginName': username,
    'password': password,
    'vericode': vericode
}
# 发送请求
s = requests.Session()
s.get(url_first)
s.get(url_vericode)
s.post(url_first, data=data)
# 访问 资产管理页
# resp = s.get(url_asset)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)


# 打开资产新增
url_asset_add = rf'{url}/bsams/front/asset/asset_new.do'
resp = s.get(url_asset_add)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)
# 资产新增
add_title = {
    'title': '遥遥领先',
    'storageId': '维信科技发展有限公司',
    'providerId': '总经理办公室'
}
resp = s.post(url_asset_add, data=add_title)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)

# 打开资产修改页面
url_asset_mod = rf'{url}/bsams/front/asset/asset_update.do'
asset_id = {'id': '1745'}
s.get(url_asset_mod, params=asset_id)

mod_title = {
    'title': '遥遥领先',
    'storageId': '维信科技发展有限公司',
    'providerId': '总经理办公室'
}
# 修改资产
resp = s.post(url_asset_add, data=mod_title)
# 资产借用
url_asset_loan = rf'{url}/bsams/front/asset/asset_borrow.do'
asset_loan_id = {'id': '1745'}
resp = s.get(url_asset_loan, params=asset_loan_id)

loan_data = {
    'id': '1745',
    'departId': '财务部',
    'remark': '遥遥领先遥遥领先遥遥领先'
}
resp = s.post(url_asset_loan, data=loan_data)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)

# 资产归还
url_asset_return = rf'{url}/bsams/front/asset/asset_giveBack.do'
asset_return_id = {'assetId': '1720'}

resp = s.post(url_asset_return, data=asset_return_id)

# 查询存放地点
url_location = rf'{url}/bsams/front/asset_storage/asset_storage_list.do'
location_data = {
    'pageNo': '',
    'status': '',
    'title': ''

}
resp = s.post(url_location, data=location_data)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)

# 查询供应商
url_supplier = rf'{url}/bsams/front/asset_provider/asset_provider_list.do'
supplier_data = {
    'pageNo': '',
    'status': '',
    'title': ''

}
resp = s.post(url_supplier, data=supplier_data)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)

# 查询个人信息
url_user = rf'{url}/bsams/front/asset_user/user_info.do'

resp = s.get(url_user)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)

# 修改手机号
url_phone = rf'{url}/bsams/front/asset_user/update_phone.do'
phone_data = {
    'assetUserId': '230',
    'phone': '17534741512'
}
resp = s.post(url_phone, data=phone_data)

# 修改密码
url_pwd = rf'{url}/bsams/front/asset_user/update_password_pre.do'
pwd_id = {'assetUserId': '230'}
resp = s.get(url_user, params=pwd_id)
pwd_data = {
    'assetUserId': '123456',
    'oldPassword': '123456',
    'newPassword': '123456'
}
resp = s.post(url_pwd, data=pwd_data)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)
